
class CartService

  class << self

    def wrap_carts_with_product_and_channel carts
      grouped = carts.group_by(&:channel_id)

      grouped.inject({}) do |result, (channel_id, members)|
        channel = Channel.find(channel_id)
        result[channel.name] = { channel_id: channel_id, carts: members.map{|x| ActiveModelSerializers::SerializableResource.new(x)}}
        result
      end
    end

  end

end
